package com.compty.paint.web.member;

import java.util.Date;
import java.util.List;

import com.compty.core.struts2.BaseAction;
import com.compty.paint.domain.Goods;
import com.compty.paint.domain.TransactionRecord;
import com.compty.paint.manager.GoodsManager;
import com.compty.paint.manager.TransactionRecordManager;
import com.compty.paint.util.Constants;
import com.compty.security.domain.User;

/**
 * 账务查询(结算查询)
 */
public class AccountAction extends BaseAction<TransactionRecord> {
	
	private static final long serialVersionUID = 3779676398192341935L;
	
	private TransactionRecordManager transactionRecordManager;
	private GoodsManager goodsManager;
	
	private Date startDate;
	private Date endDate;
	
	/**
	 * 查询用户相关的成交记录
	 */
	@SuppressWarnings("unchecked")
	public String queryTransactions(){
		
		Object user_obj =  session.getAttribute(Constants.Userinfo);
		User userInfo = user_obj !=  null ? (User)user_obj:null;

        this.page =  transactionRecordManager.queryForPage(curPage, pageSize,userInfo,startDate,endDate,filterTxt,filterValue);
        List list = (List)page.getResult();
        
        float totalAccount = 0f;
        for (int i = 0; i < list.size(); i++) {
        	TransactionRecord transactionRecord =  (TransactionRecord) list.get(i);
        	
        	totalAccount += transactionRecord.getDeal_price();
        	
        	int goods_id = transactionRecord.getGoods_id();
        	if( goods_id != 0 ){
        		Goods goods = goodsManager.findById(goods_id);
        		transactionRecord.setGoods(goods);
        	}
		}
        
        request.setAttribute("totalAccount", totalAccount);
	
		return "transactions_list";
	}

	public void setTransactionRecordManager(TransactionRecordManager transactionRecordManager) {
		this.transactionRecordManager = transactionRecordManager;
	}

	public void setGoodsManager(GoodsManager goodsManager) {
		this.goodsManager = goodsManager;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

}
